package indi.henry.demo.aspect;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import indi.henry.demo.service.CounterService;
import lombok.RequiredArgsConstructor;

/**
 * The aspect to proceed the counting operation after target methods
 * 
 * @author Henry Hu
 */
@Aspect
@Component
@RequiredArgsConstructor
public class CounterAspect {
    
    private final CounterService counterService;

    @After("execution(* indi.henry.demo.service.RedisService.getUrlById(..)) && args(id)")
    public void postCountingForGetting(String id) {
        counterService.addGet(id);
    }

    @After("execution(* indi.henry.demo.service.RedisService.setUrlWithId(..)) && args(id, url)")
    public void postCountingForSetting(String id, String url) {
        counterService.addSet(id);
    }
}
